package com.imooc.disruptor.client;

import com.imooc.disruptor.entity.TranslatorData;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yqc 2018/10/16
 */
@Slf4j
public class ClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        try {
            TranslatorData response = (TranslatorData) msg;
            log.info("Client端: id = {}, name = {}, message = {}",
                    response.getId(), response.getName(), response.getMessage());
        } finally {
            //一定要注意用完了缓存要进行释放
            ReferenceCountUtil.release(msg);
        }
    }
}
